package cn.edu.neusoft.zengweidong707.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText login_name;
    private EditText login_password;
    private Button reg;
    private Button login;
    private static String TAG = "Activity_1";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: ");
        setContentView(R.layout.activity_main);

        login_name = (EditText)findViewById(R.id.reg_name);
        login_password = (EditText)findViewById(R.id.reg_password);
        login = (Button)findViewById(R.id.login);
        reg = (Button)findViewById(R.id.reg);

        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String message = "China";

                Intent intent = new Intent(MainActivity.this, Activity_Reg.class);

                intent.putExtra("message", message);

                startActivityForResult(intent, 1);
                //finish();
            }
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case 1 :
                if(resultCode == RESULT_OK) {
                    String string = data.getStringExtra("return");
                    Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
                    //login_name.setText(string);
                }

        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart: ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop: ");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume: ");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause: ");
    }
}
